package com.itwlj.controller.admin;

import com.itwlj.dto.UserDTO;
import com.itwlj.dto.UserPageQueryDTO;
import com.itwlj.result.PageResult;
import com.itwlj.result.Result;
import com.itwlj.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理
 */
@RestController("adminUser")
@RequestMapping("admin/user")
@Api(tags = "子分类相关接口")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 新增用户
     *
     * @param userDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增用户")
    public Result<String> insert(@RequestBody UserDTO userDTO) {
        log.info("新增用户：{}", userDTO);
        userService.insert(userDTO);
        return Result.success();
    }

    /**
     * 用户分页查询
     *
     * @param userPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("用户分页查询")
    public Result<PageResult> page(UserPageQueryDTO userPageQueryDTO) {
        log.info("用户分页查询：{}", userPageQueryDTO);
        PageResult pageResult = userService.page(userPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 修改用户
     *
     * @param userDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改用户")
    public Result<String> update(@RequestBody UserDTO userDTO) {
        log.info("修改用户：{}", userDTO);
        userService.update(userDTO);
        return Result.success();
    }

    /**
     * 用户启用禁用
     *
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("用户启用禁用")
    public Result<String> startOrStop(@PathVariable Integer status, Long id) {
        log.info("用户启用禁用：{}，状态：{}", id, status);
        userService.startOrStop(status, id);
        return Result.success();
    }
}
